<?php
class dbQuery{
	public function query( $sql = "" ){		
		if ( !empty($sql) ){
			return mysql_query($sql);
			//return mysql_insert_id();
		}else{
			return "";
		}
	}
	public function getInsertid( $res ){
		return mysql_insert_id();
	}
	public function queryFetchObject( $sql = "" ){
		$results = Array();		
		$res = dbQuery::query( $sql );		
		while( $rows = mysql_fetch_object($res) ){
			$results[] = $rows;
		}
		if (sizeof($results) == 1){
			return $results[0];
		}else{		
			return $results;
		}
	}
	
	public function queryFetchArray( $sql = "" ){
		$results = Array();		
		$res = dbQuery::query( $sql );		
		while( $rows = mysql_fetch_array($res) ){
			$results[] = $rows;
		}
		if (sizeof($results) == 1){
			return $results[0];
		}else{		
			return $results;
		}
	}
	
	public function formatRequest( $data = NULL ){
		$sql = "";
		$where = " WHERE ";
		if ( !empty($data) ){
			foreach($data['sql'][0] as $value=>$key){
				if ($key != 'id'){
					$sql .= "`".$key."`='".$data[$value]."', ";
				}else{
					$where .= "`".$key."`='".$data[$value]."', ";
				}
			}
			$sql = substr(trim($sql), 0, -1);
			$sql = substr(trim($sql.$where), 0, -1);
		}
		return $sql;
	}
}
?>